package ar.com.ford.it.fullEconomics.struct;

import java.math.BigDecimal;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesr04Agreemitem;
import ar.com.ford.it.fullEconomics.util.FullEconomicsDateUtil;

public class AgreementReportRow {

    private String econLevel;
    private String itemName;
    private BigDecimal currPrice;
    private BigDecimal fulleAmount;
    private BigDecimal fullePercent;
    private BigDecimal requestAmount;
    private BigDecimal requestPercent;
    private BigDecimal payPolAmount;
    private BigDecimal payPolPercent;
    private BigDecimal lastAgreemAmount;
    private BigDecimal lastAgreemPercent;

    public AgreementReportRow() {
        this.econLevel = "";
        this.itemName = "";
        this.currPrice = new BigDecimal(0);
        this.fulleAmount = new BigDecimal(0);
        this.fullePercent = new BigDecimal(0);
        this.requestAmount = new BigDecimal(0);
        this.requestPercent = new BigDecimal(0);
        this.payPolAmount = new BigDecimal(0);
        this.payPolPercent = new BigDecimal(0);
        this.lastAgreemAmount = new BigDecimal(0);
        this.lastAgreemPercent = new BigDecimal(0);

    }

    public void calculatePercents() {
        if (fulleAmount.compareTo(new BigDecimal(0)) != 0)
            fullePercent = fulleAmount.subtract(currPrice).divide(currPrice, 5,
                    BigDecimal.ROUND_HALF_EVEN).multiply(new BigDecimal(100));
        if (requestAmount.compareTo(new BigDecimal(0)) != 0)
            requestPercent = requestAmount.subtract(currPrice).divide(
                    currPrice, 5, BigDecimal.ROUND_HALF_EVEN).multiply(
                    new BigDecimal(100));
        if (payPolAmount.compareTo(new BigDecimal(0)) != 0)
            payPolPercent = payPolAmount.subtract(currPrice).divide(currPrice,
                    5, BigDecimal.ROUND_HALF_EVEN)
                    .multiply(new BigDecimal(100));
        if (lastAgreemAmount.compareTo(new BigDecimal(0)) != 0)
            lastAgreemPercent = lastAgreemAmount.subtract(currPrice).divide(
                    currPrice, 5, BigDecimal.ROUND_HALF_EVEN).multiply(
                    new BigDecimal(100));
    }

    public BigDecimal getCurrPrice() {
        return currPrice;
    }

    public void setCurrPrice(BigDecimal currPrice) {
        this.currPrice = currPrice;
    }

    public String getEconLevel() {
        return econLevel;
    }

    public void setEconLevel(String econLevel) {
        this.econLevel = econLevel;
    }

    public void setEconLevel(Teesr04Agreemitem item) {
        this.econLevel = FullEconomicsDateUtil.getMonth(item
                .getTeesr03Agreement().getEesr03AgreeEcolevelDateY())
                + "-"
                + FullEconomicsDateUtil.getYear(item.getTeesr03Agreement()
                        .getEesr03AgreeEcolevelDateY());
    }

    public BigDecimal getFulleAmount() {
        return fulleAmount;
    }

    public void setFulleAmount(BigDecimal fulleAmount) {
        this.fulleAmount = fulleAmount;
    }

    public BigDecimal getFullePercent() {
        return fullePercent;
    }

    public void setFullePercent(BigDecimal fullePercent) {
        this.fullePercent = fullePercent;
    }

    public BigDecimal getLastAgreemAmount() {
        return lastAgreemAmount;
    }

    public void setLastAgreemAmount(BigDecimal lastAgreemAmount) {
        this.lastAgreemAmount = lastAgreemAmount;
    }

    public BigDecimal getLastAgreemPercent() {
        return lastAgreemPercent;
    }

    public void setLastAgreemPercent(BigDecimal lastAgreemPercent) {
        this.lastAgreemPercent = lastAgreemPercent;
    }

    public BigDecimal getPayPolAmount() {
        return payPolAmount;
    }

    public void setPayPolAmount(BigDecimal payPolAmount) {
        this.payPolAmount = payPolAmount;
    }

    public BigDecimal getPayPolPercent() {
        return payPolPercent;
    }

    public void setPayPolPercent(BigDecimal payPolPercent) {
        this.payPolPercent = payPolPercent;
    }

    public BigDecimal getRequestAmount() {
        return requestAmount;
    }

    public void setRequestAmount(BigDecimal requestAmount) {
        this.requestAmount = requestAmount;
    }

    public BigDecimal getRequestPercent() {
        return requestPercent;
    }

    public void setRequestPercent(BigDecimal requestPercent) {
        this.requestPercent = requestPercent;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public void setItemName(Teesr04Agreemitem agreemItem, String defaultName) {
        if (agreemItem.getEesr04AgritmTypeCodeC().equalsIgnoreCase("P"))
            this.itemName = agreemItem.getTeesp04Supply().getTeesp01Part()
                    .getEesp01PartDescriptionX();
        else if (agreemItem.getEesr04AgritmTypeCodeC().equalsIgnoreCase("C"))
            this.itemName = agreemItem.getTeesp02Commodity()
                    .getEesp02CommodityNameN();
        else
            this.itemName = defaultName;
    }

}
